import os
import random
import tensorflow as tf
import numpy as np
def set_random_seed(seed=0):
    random.seed(seed)
    np.random.seed(seed)
    tf.random.set_seed(seed)
    os.environ['PYTHONHASHSEED'] = str(seed)
    os.environ['TF_DETERMINISTIC_OPS'] = '1'

def configure_hardware():
    gpus = tf.config.experimental.list_physical_devices('GPU')
    if gpus:
        try:
            # 指定使用GPU 1
            tf.config.experimental.set_visible_devices(gpus[5], 'GPU')
            # 设置GPU显存分配为按需增长
            tf.config.experimental.set_memory_growth(gpus[5], True)
        except RuntimeError as e:
            print(e)
    

class DynamicConfig:
    def __init__(self):
        # 路径配置
        self.cwd = os.getcwd()
        self.pardir = os.path.dirname(self.cwd)
        self.MODEL_SELECT = "LSTM"  # 默认值
        self.WEATHER_SELECT = "ALL" # 默认值
        self.IMG_SIDE_LEN = 64
        self.NUM_LOG_TERM = 16
        self.NUM_COLOR_CHANNEL = 3
        self.BATCH_SIZE = 256
        self.EPOCHS = 400
        self.LEARNING_RATE = 3e-4
        self.VAL_RATIO = 0.2
        self.PATIENCE = 5

    @property
    def data_folder(self):
        """根据当前 WEATHER_SELECT 动态生成 data_folder 路径"""
        weather_subdir = self.WEATHER_SELECT.capitalize()
        return os.path.join(self.pardir, "solar_former", "data", "data_forecast", weather_subdir)

    @property
    def output_folder(self):
        """根据当前 WEATHER_SELECT 动态生成 output_folder 路径"""
        weather_subdir = self.WEATHER_SELECT.lower()
        return os.path.join(self.pardir, "solar", "data", "model_output", 'SUNSET_forecast_2017_2019_data', weather_subdir)


# 创建全局配置实例,供整个工程使用
config = DynamicConfig()